<template>
    <div class="layout-route">
        <div class="card card-search">
            <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
            </el-form>
        </div>
        <div class="card">
            <el-table v-loading="loading" :data="tableData" border script show-summary>
                <el-table-column label="SPU" prop="spu" min-width="200"></el-table-column>
                <el-table-column label="数量" prop="quantity" min-width="100"></el-table-column>
                <el-table-column label="售后率" prop="percentage" min-width="100"></el-table-column>
            </el-table>
            
            <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList" />
        </div>
    </div>
</template>

<script>
import { queryAfterSalesFeedbackList, getQuestionList } from '@/api/order'
import { parseTime } from '@/utils/quickadmin'
export default {
    name: 'AfterSalesFeedbackList',
    props: {
        params: Object,
        type: Object,
    },
    data() {
        return {
            // 遮罩层
            loading: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 表格数据
            tableData: [],
            pageInfo: {
                page: 1,
                limit: 10,
            },
            dict: {
                questionList: [],
            },
        }
    },
    watch: {
        params: {
            handler(val) {
                if (this.type.createtime && Object.keys(this.type.createtime).length === 2) {
                    this.type.createtime = [
                        parseTime(this.type.createtime['0'], 'y-m-d'),
                        parseTime(this.type.createtime['1'], 'y-m-d')
                    ];
                }
                this.queryParams = this.type
                this.queryParams.ReasonForRefundId = this.params.ReasonForRefundId
                this.handleQuery()
            },
            immediate: true,
            deep: true,
        },
    },
    async mounted() {
        // try {
        //     const questionData = await getQuestionList()
        //     this.dict.questionList = questionData?.data ?? []
        // } catch (error) {
        //     //
        //     console.log(error)
        // }

        // this.getList()
    },
    methods: {
        //列表
        getList() {
            this.loading = true
            const qyparams = {
                ...this.pageInfo,
                ...this.queryParams,
            }
            queryAfterSalesFeedbackList(qyparams)
                .then(response => {
                    this.tableData = response.data.list
                    // this.tableData = response.data.map((item, index) => {
                    //     item.rowKey = `${item.spu}--${index}`
                    //     if (item.children) {
                    //         item.children.map((pre, i) => {
                    //             pre.rowKey = `${item.spu}--${index}--${i}`
                    //         })
                    //     }
                    //     return { ...item }
                    // })
                    this.total = response.data?.total ?? 0
                })
                .finally(() => {
                    this.loading = false
                })
        },
        // 搜索按钮操作
        handleQuery() {
            this.pageInfo.page = 1
            this.getList()
        },

        // 重置按钮操作
        resetQuery() {
            this.resetForm('queryForm')

            this.handleQuery()
        },
    },
}
</script>

<style></style>
